Skip to content

Scanner 13 Nov: hot-fixes from the 7 T session - #174

Merged
mcencini merged 5 commits into
mainfrom
scanner-1113-hotfixes
Nov 13, 2026
Merged

mcencini merged 5 commits into
mainfrom
scanner-1113-hotfixes

Conversation

@mcencini

@mcencini mcencini commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Hot-fixes from the 13 Nov 7 T session, collected here and merged after the scanner confirms them.

Fix How it is hot-fixed Confirmed on the scanner
tools.estimate_epi_echo_phase: odd/even phase (constant + linear) of every echo of an EPI train from a blip-free reference train; each reversed echo is fitted against the mean of its forward neighbours, which cancels the off-resonance phase growing along the train; the first/last reversed echo takes the nearest interior fit. estimate_epi_phase and the new function share _fit_odd_even. Used by pulserver's EpiPhaseCorrection (pulserver #382). bartorch/tools/_correct/{_epi,__init__}.py replaced in the scanner's EnvPulserver site-packages (bundle build/scanner-2026-11-13/hotfix-epi-ref/) [ ]
tools.apply_susceptibility: an image corrected with a known displacement field, PyHySCO's model (blip-up sampled at x + b(x), intensity x (1 + db/dx); blip-down at x - b(x)), linear along the phase encode, circular; pure torch. Used by pulserver's EpiRecon to estimate once per slice and apply to every image (pulserver #382). bartorch/tools/_correct/{_susceptibility,__init__}.py replaced in the scanner's EnvPulserver site-packages (bundle build/scanner-2026-11-13/hotfix-hysco-once/) [ ]

Checks: tests/test_correct_epi.py 20 passed, 5 skipped (no CUDA device), three new tests for the per-echo fit. docs/api/tools.md lists the function; the EPI tour still shows the navigator fit and gets a reference-train section after the scanner confirms.

Checks (apply_susceptibility): tests/test_apply_susceptibility.py 7 passed. Exam 5195 series 3: applying correct_susceptibility(...).field_map to the blip-up input reproduces its blip_up with correlation 0.99998 (max difference 3.9 %: correct_susceptibility interpolates the pre-aligned image a second time; the same composition matches to 8e-15 away from the edges). docs/api/tools.md gets the row after the scanner confirms. test_correct_susceptibility.py::test_corrected_pair_is_in_the_intensity_units_of_the_input fails at b83b248 already (pre-alignment), untouched here.

🤖 Generated with Claude Code

…ee EPI reference train

The reference is the imaging train with every phase encode at zero; each
reversed echo is fitted against the mean of its forward neighbours, which
cancels the off-resonance phase growing along the train, with the fit
estimate_epi_phase uses (now shared as _fit_odd_even). An echo with a
forward neighbour on one side only takes the nearest interior fit.

Scanner hot-fix, 13 Nov 7 T session: pulserver's EpiPhaseCorrection fits
the reference train the EPI sequences now play in a dummy shot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.38554% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/bartorch/tools/_correct/_epi.py 94.11% 2 Missing ⚠️
src/bartorch/tools/_correct/_susceptibility.py 97.87% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

…PyHySCO

A centre frequency off the sample's resonance displaces a reversed-phase-encode
pair uniformly in opposite directions, by many voxels when the phase-encode
bandwidth per voxel is low (exam 5195 series 3: 64 voxels between the pair at
5.3 Hz/voxel). PyHySCO, estimating the field from zero, converged to a wrong
solution. The pair's profiles along the phase-encoding axis are now
cross-correlated, each image is moved half the lag towards the other, PyHySCO
estimates the rest, and the removed displacement is added to field_map
(prealign=True by default).

Series 3: corrected up/down correlation 0.47 -> 0.97; the sphere's height/width
1.87/1.71 -> 1.23/1.15 (input 1.28/1.20).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mcencini

Copy link
Copy Markdown
Collaborator Author

Added b83b248: correct_susceptibility removes the uniform displacement before PyHySCO (prealign=True), folded into field_map. Hot-fixed 13 Nov as site-packages/bartorch/tools/_correct/_susceptibility.py (bundle build/scanner-2026-11-13/hotfix-hysco-prealign). Exam 5195 series 3 offline: corrected up/down correlation 0.47 → 0.97, sphere height/width 1.87/1.71 → 1.23/1.15. Scanner confirmation pending.

🤖 Generated with Claude Code

mcencini and others added 3 commits November 13, 2026 12:20
…t field

The blip-up image sampled at x + b(x) with intensity 1 + db/dx (blip-down
at x - b(x), 1 - db/dx), PyHySCO's model, linear along the phase encode and
wrapping around; pure torch, no PyHySCO. A field estimated once by
correct_susceptibility corrects every later image of the same slice, as
applytopup --method=jac does.

On exam 5195 series 3 (192x192, 1.1458 mm), applying the estimated field to
the blip-up input reproduces correct_susceptibility's blip_up with
correlation 0.99998; the 3.9 % max difference is the second interpolation
of the pre-aligned image (the composition matches to 8e-15 inside).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fractional pre-alignment interpolated the pair once more before PyHySCO,
which blurred it: test_corrected_pair_is_in_the_intensity_units_of_the_input
missed its bound (error 0.2441 against 0.2439), and applying the field to
the input differed from the corrected image by up to 3.9 %. A roll by whole
voxels does not blur; PyHySCO takes the remaining half voxel at most.
Series 3 / 5: corrected up/down correlation 0.965 / 0.93 (fractional:
0.966 / 0.938). susceptibility tests: 12 no-argument tests pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mcencini
mcencini marked this pull request as ready for review November 13, 2026 19:00
@mcencini
mcencini merged commit 003a742 into main Nov 13, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants